<?php

class Application_Model_DbTable_BookingDate extends Zend_Db_Table_Abstract
{

    protected $_name = 'booking_date';

    public function getBookingDate($venue_id,$start_date,$end_date){
        $query = $this->select();
        $query->from(array('bd'=>'booking_date'));
        $query->joinInner(array('b'=>'booking'), 'bd.booking_id = b.booking_id', array('vid'=>'b.venue_id'));
        $query->where("b.venue_id = $venue_id AND bd.date >= '$start_date' AND bd.date <= '$end_date'");
        $query->setIntegrityCheck(false);

        return $this->fetchAll($query);
    }

    public function getBookingDateInMonth($venue_id,$month,$year){
        $nextMonth = ($month<12)? $month+1 : 1;
        $nextYear = ($month<12)? $year : $year+1;

        $date1 = date("Y-m-d", mktime(0,0,0,$month,1,$year));
        $date2 = date("Y-m-d", mktime(0,0,0,$nextMonth,1,$nextYear));

        $query = $this->select();
        $query->from(array('bd'=>'booking_date'));
        $query->joinInner(array('b'=>'booking'), 'bd.booking_id = b.booking_id', array('vid'=>'b.venue_id'));
        $query->where("b.venue_id = $venue_id AND bd.date >= '$date1' AND bd.date < '$date2'");
        $query->setIntegrityCheck(false);

        return $this->fetchAll($query);
    }
}

